<?php
  class DB
  {
      var $conn_id=0;
      
      function DB($dhost,$duser,$dpass,$dname)
      {
         $this->conn_id=mysqli_connect($dhost,$duser,$dpass,$dname);
        if(mysqli_connect_errno())
        {
           halt("连接错误");
        }
      }
      
      function close()
      {
          return mysqli_close($this->conn_id);
      }
      
      function query($sql)
      {
          $result=$this->conn_id->query($sql);
          if(!$result)
          {
              halt('query出错');
          }

          return $result;
      }

      //返回行数
      function count($link)
      {
         return $link->num_rows;
      }
      
      //
      function getdata($link)
      {
          return mysqli_fetch_array($link,MYSQLI_BOTH);
      }
      function getone($link)
      {
          $cc= mysqli_fetch_array($link,MYSQLI_BOTH);
          return $cc[0];
      }
      
      
     //确认是否登录
     function islogin()
     {
        $userid=Get_Cookie("user"); 
        $query=$this->query("select * from online where userid=$userid");
        $re=false;
        if($this->count($query)==1)
        {
            $dd=$this->getdata($query);
            $re=($dd[0]==$userid?true:false);
        }
        //登记登录信息
        if($re)
        {
            $la=time();
            $dd["lasttime"]=$la;
            $userid=$dd["userid"];
            $this->query("update online set lasttime=$la where userid=$co");    
        }
        //re返回是否登录，userid，ip，lasttime最后访问时间，lx用户类型
        return array($re,$userid,$dd["ip"],$dd["lasttime"],$dd["lx"]);
     }      
  }
  
//结束函数
function halt($msg)
{
    echo $msg;
}



?>
